<!--继承基文件-->
{% extends "base.html" %}
{% load static %}
<!--标题-->
{% block title %} 用户列表 {% endblock title %}

<!--内容-->
{% block content %}
    <div class="col-lg-9">
        <div class="panel panel-info">
            <div class="panel-heading">
                <span style="font-size: 24px">用户列表</span>
            </div>
            <div class="panel-body">
                <table class="table table-striped table-bordered table-hover table-condensed">
                    <tr class="info">
                        <th>序号</th>
                        <th>ID</th>
                        <th>用户名</th>
                        <th>手机号</th>
                        <th>部门</th>
                        <th>操作</th>
                    </tr>
                    {% for user_obj in user_list %}
                        <tr>
                            <td>{{ forloop.counter }}</td>
                            <td>{{ user_obj.pk }}</td>
                            <td>{{ user_obj.username }}</td>
                            <td>{{ user_obj.phone }}</td>
                            <td>{{ user_obj.dep.name }}</td>
                            <td>
                                <button class="btn btn-danger" onclick="delUser({{ user_obj.pk }})">删除</button>
                                <a class="btn btn-success" href="{% url 'editUser' user_obj.pk %}">编辑</a>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        </div>
    </div>
{% endblock content %}
{% block jsFiles %}
    <script src="{% static 'js/jquery.cookie.js' %}"></script>
    <script>
        function delUser(pk){
            $.ajax({
                url: {% url 'delUser' %},
                type: 'post',
                data:{
                    pk:pk,
                    csrfmiddlewaretoken: $.cookie('csrftoken')
                },
                success:function(ret){
                    alert(ret.status);
                    window.history.go();
                },
                error:function(ret){
                    console.log(ret);
                }
            });
        }
    </script>
{% endblock jsFiles %}
